package dreammachine

class DreamController {

    def dreamsService
    def index() {

        log.info("Returning the dreams list")
        def result = dreamsService.dreamsList();
        if(result == null){
            render("No dream to display")
        }
        else{
            [dreams : result]
        }

    }
    def showCreate(){
        render(view: "create")
    }

    def create(){

        log.info("Creating a dream")
        def name = params.dreamTitle
        def content = params.dreamContent
        def result = dreamsService.create(name,content)
        if (result){
           [view: "index", action: index() ]
        }
    }
}
